/* 
 * File:   ObjFactory.cpp
 * Author: mauro
 * 
 * Created on 8 de septiembre de 2014, 18:23
 */

#include "ObjFactory.h"
#include "SkinFactory.h"
#include "Dot.h"

ObjFactory::ObjFactory() {
}


//creo un objeto y asigno un mundo y render.
ObjFactory::ObjFactory(b2World &world, SDL_Renderer *render, int pixelWidth, int pixelHeight, int unitWidth, int unitHeight) {
    this->world = &world;
    BodyFactoryDynamic *factoryDynamic = new BodyFactoryDynamic(world);
    this->factoryDynamic = factoryDynamic;
    BodyFactoryStatic *factoryStatic = new BodyFactoryStatic(world);
    this->factoryStatic = factoryStatic;
    SkinFactory *skinFactory = new SkinFactory(render,pixelWidth, pixelHeight,  unitWidth, unitHeight );
    this->skinFactory = skinFactory;
    this->pixelWidth = pixelWidth;
    this->pixelHeight = pixelHeight;
    this->unitWidth = unitWidth;
    this->unitHeight = unitHeight;
}

ObjFactory::~ObjFactory() {
    delete this->factoryDynamic;
    delete this->factoryStatic;
    delete this->skinFactory;
//    printf("Destructor ObjFactory \n");
}

Object* ObjFactory::getCharacter(b2Vec2 * pos, b2Vec2* size) {
    b2Body *body;
    body = this->factoryDynamic->getCharacter(pos, size);
    Object* obj = new Object(body, this->skinFactory);
    return obj;
}

Object* ObjFactory::getObjectParallellogram(bool flagStatic, b2Vec2* pos, b2Vec2* size, float alpha, float mass, float rotation) {
    b2Body* body;
    
    if (!flagStatic) {
        body = this->factoryDynamic->getBodyParallellogram(pos, size, alpha, mass, rotation);
    } else {
        body = this->factoryStatic->getBodyParallellogram(pos, size, alpha, rotation);
    }

    Object* obj = new Object(body, this->skinFactory);
    return obj;
}

Object* ObjFactory::getObjectTrapezium(bool flagStatic, b2Vec2* pos, b2Vec2* size, float alpha, float beta, float mass, float rotation){
    b2Body* body;
    if(!flagStatic){
        body = this->factoryDynamic->getBodyTrapezium(pos, size, alpha, beta, mass,rotation);
    } else {
        body = this->factoryStatic->getBodyTrapezium(pos, size, alpha, beta, rotation);    
    }

    Object* obj = new Object(body, this->skinFactory);
    return obj;

}

Object* ObjFactory::getObject(bool flagStatic,b2Vec2 * pos, b2Vec2* size, float scale, float mass, int sides, float rotation) {            
    b2Body *body;        
    if (!flagStatic) {
        body = this->factoryDynamic->getBody(sides, pos, size, scale, mass,rotation);
    } else {
        body = this->factoryStatic->getBody(sides, pos, size, scale, rotation);
    }
    
    Object* obj = new Object(body, this->skinFactory);
    return obj;
}

SDL_Renderer* ObjFactory::getRender() {
    return this->skinFactory->getGameRenderer();
}

int ObjFactory::getPixelWidth() {
    return this->pixelWidth;
}

int ObjFactory::getPixelHeight() {
    return this->pixelHeight;
}

int ObjFactory::getUnitWidth() {
    return this->unitWidth;
}

int ObjFactory::getUnitHeight() {
    return this->unitHeight;
}

